<template>
    <el-container>
      <!-- 页面标题 -->
      <el-header class="carbon-audit-header">
        <h2>企业碳排放数据审核</h2>
      </el-header>
  
      <!-- 数据列表区域 -->
      <el-main>
        <el-table :data="emissionData" style="width: 100%">
          <el-table-column prop="enterpriseName" label="企业名称" width="180"></el-table-column>
          <el-table-column prop="emissionDate" label="排放日期" width="160"></el-table-column>
          <el-table-column prop="carbonEmission" label="碳排放量（吨）"></el-table-column>
          <el-table-column prop="attachment" label="附件">
            <template slot-scope="scope">
              <a :href="scope.row.attachmentUrl" target="_blank">查看附件</a>
            </template>
          </el-table-column>
          <el-table-column prop="auditStatus" label="审核状态">
            <template slot-scope="scope">
              <el-tag :type="getStatusTagType(scope.row.auditStatus)">{{getStatusText(scope.row.auditStatus)}}</el-tag>
            </template>
          </el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scope">
              <el-button v-if="scope.row.auditStatus === '待审核'" @click="handleAudit(scope.$index, scope.row)">审核</el-button>
              <el-button type="success" v-if="scope.row.auditStatus === '审核通过'" disabled>已通过</el-button>
              <el-button type="danger" v-if="scope.row.auditStatus === '审核未通过'" disabled>未通过</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-main>
  
      <!-- 审核弹窗 -->
      <el-dialog title="审核详情" :visible.sync="auditDialogVisible" width="50%">
        <el-form ref="auditForm" :model="currentAuditItem" label-width="80px">
          <el-form-item label="审核结论">
            <el-select v-model="currentAuditItem.auditConclusion" placeholder="请选择审核结论">
              <el-option label="审核通过" value="审核通过"></el-option>
              <el-option label="审核未通过" value="审核未通过"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="审核理由">
            <el-input type="textarea" v-model="currentAuditItem.auditReason" autosize></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="auditDialogVisible = false">取消</el-button>
          <el-button type="primary" @click="submitAudit">提交审核</el-button>
        </div>
      </el-dialog>
    </el-container>
  </template>
  
  <script>
  export default {
    data() {
      return {
        emissionData: [
  {
    enterpriseName: '企业A',
    emissionDate: '2022-01-01',
    carbonEmission: '500',
    attachmentUrl: 'https://www.hongyuan3e.com/carbon_data/index.html',
    auditStatus: '待审核'
  },
  {
    enterpriseName: '企业B',
    emissionDate: '2022-02-01',
    carbonEmission: '700',
    attachmentUrl: 'https://www.carbonstop.net/ccdb5',
    auditStatus: '待审核'
  },
  {
    enterpriseName: '企业C',
    emissionDate: '2022-03-01',
    carbonEmission: '450',
    attachmentUrl: 'https://roll.sohu.com/a/583076799_121357745',
    auditStatus: '审核通过'
  },
  {
    enterpriseName: '企业D',
    emissionDate: '2022-04-01',
    carbonEmission: '600',
    attachmentUrl: 'https://www.carbonstop.net/carbonexchangecamp/',
    auditStatus: '审核未通过'
  },
  // 新增三条数据
  {
    enterpriseName: '企业E',
    emissionDate: '2022-05-01',
    carbonEmission: '800',
    attachmentUrl: 'https://www.hongyuan3e.com/page-carbon-offset.html',
    auditStatus: '待审核'
  },
  {
    enterpriseName: '企业F',
    emissionDate: '2022-06-01',
    carbonEmission: '900',
    attachmentUrl: 'https://www.hongyuan3e.com/data/index.html',
    auditStatus: '审核通过'
  },
  {
    enterpriseName: '企业G',
    emissionDate: '2022-07-01',
    carbonEmission: '750',
    attachmentUrl: 'https://www.hongyuan3e.com/page-carbon-offset.html',
    auditStatus: '审核未通过'
  },
],
        auditDialogVisible: false,
        currentAuditItem: {}
      };
    },
    methods: {
    getStatusTagType(status) {
      switch (status) {
        case '待审核':
          return '';
        case '审核通过':
          return 'success';
        case '审核未通过':
          return 'danger';
        default:
          return '';
      }
    },
    getStatusText(status) {
      switch (status) {
        case '待审核':
          return '待审核';
        case '审核通过':
          return '已通过';
        case '审核未通过':
          return '未通过';
        default:
          return '未知状态';
      }
    },
    handleAudit(index, row) {
      this.currentAuditItem = Object.assign({}, row); // 避免直接修改原始数据
      this.auditDialogVisible = true;
    },
    submitAudit() {
      // 提交审核请求

          this.$message({
            message: '审核成功',
            type: 'success'
          });
       
        this.auditDialogVisible = false;
    }
  },
  };
  </script>